package com.timedomain.him.remake.core;
import java.nio.ByteBuffer;

import static com.un4seen.bass.BASS.*;

public class BassUtils {

    public static long GetDuration(int channel){
        long bytes = BASS_ChannelGetLength(channel,BASS_POS_BYTE);
        return (long) (BASS_ChannelBytes2Seconds(channel,bytes) * 1000d);
    }

    public static long GetPosition(int channel){
        long bytes = BASS_ChannelGetPosition(channel,BASS_POS_BYTE);
        return (long) (BASS_ChannelBytes2Seconds(channel,bytes) * 1000d);
    }

    public static void SetPosition(int channel,long positionMs){
        long bytes = BASS_ChannelSeconds2Bytes(channel,((double)positionMs) / 1000.0d);
        BASS_ChannelSetPosition(channel,bytes,BASS_POS_BYTE);
    }

    public static float GetPeak(int channel){
        int levelCompat = BASS_ChannelGetLevel(channel);
        if(levelCompat == -1){return 0;}
        int left = Utils.LOWORD(levelCompat);
        int right = Utils.HIWORD(levelCompat);
        int max = left > right ? left : right;
        return (float)max / 32768f;
    }

}
